package classWork;

import java.util.*;
import java.util.function.Predicate;
import java.util.stream.Stream;

public class Stream01 {
    public static void main(String[] args) {
        List<String> list = new ArrayList<String>();
        list.add("张三丰");
        list.add("张无忌");
        list.add("张翠山");
        list.add("王二麻子");
        list.add("张良");
        list.add("谢广坤");
        list.stream().filter(new Predicate<String>() {
            @Override
            public boolean test(String s) {
                return s.startsWith("张");
            }
        }).forEach(s -> System.out.println(s));
        list.stream().filter(s -> s.startsWith("张")).filter(s -> s.length()>2).forEach(s -> System.out.println(s));
        System.out.println("-------------------");


        Set<String> set = new HashSet<String>();
        set.add("张三丰");
        set.add("张无忌");
        set.add("张翠山");
        set.add("王二麻子");
        set.add("张良");
        set.add("谢广坤");
        set.stream().forEach(s -> System.out.println(s));
        System.out.println("-------------------");
        Map<String, Integer> map = new HashMap<String, Integer>();
        map.put("张三丰",100);
        map.put("张无忌",35);
        map.put("张翠山",55);
        map.put("王二麻子",22);
        map.put("张良",30);
        map.put("谢广坤",55);
        map.entrySet().stream().filter(stringIntegerEntry -> stringIntegerEntry.getKey().startsWith("张")).forEach(stringIntegerEntry -> System.out.println(stringIntegerEntry));
        System.out.println("-------------------");
        int[] arr = {1,2,3,4,5};
        Arrays.stream(arr).forEach(s-> System.out.println(s));
        System.out.println("------------------");
        Stream.of(1,2,3).forEach(s-> System.out.println(s));
    }
}
